package com.aiex.framework.web.base;

import com.aiex.framework.web.enums.WebErrorCodeEnum;
import lombok.Data;

@Data
public class Result<T> {
    /**
     * 错误妈
     */
    private Integer code;
    /**
     * 信息
     */
    private String message;
    /**
     * 数据
     */
    private T data;

    public static<T> Result<T> ok(){
        Result<T> result = new Result<>();
        result.setCode(WebErrorCodeEnum.SUCCESS.code);
        result.setMessage("请求成功");
        return result;
    }

    public static<T> Result<T> ok(T data){
        Result<T> result = new Result<>();
        result.setCode(WebErrorCodeEnum.SUCCESS.code);
        result.setMessage("请求成功");
        result.setData(data);
        return result;
    }

    public static<T> Result<T> error(String errorMsg){
        Result<T> result = new Result<>();
        result.setCode(WebErrorCodeEnum.FAIL.code);
        result.setMessage(errorMsg);
        return result;
    }

    public static<T> Result<T> error(Integer code, String errorMsg){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(errorMsg);
        return result;
    }


}
